//
//  YJBTradeDetailHeaderView.m
//  YunJiaBaoFirst
//
//  Created by 腾云小白龍 on 16/7/29.
//  Copyright © 2016年 腾云小白龍. All rights reserved.
//

#import "YJBTradeDetailHeaderView.h"
@interface YJBTradeDetailHeaderView()
@property (strong, nonatomic) UILabel * averageLabel; //平均价
@property (strong, nonatomic) UILabel * codeLabel;
@property (strong, nonatomic) UILabel * closePriceTextLabel;
@property (strong, nonatomic) UILabel * openPriceTextLabel;
@property (strong, nonatomic) UILabel * maxPriceTextLabel;
@property (strong, nonatomic) UILabel * minPriceTextLabel;
@property (strong, nonatomic) UILabel * changePriceTextPointLabel;
@property (strong, nonatomic) UILabel * changePriceTextPercentLabel;
@property (strong, nonatomic) UILabel * recentPriceTextLabel;
@property (strong, nonatomic) UILabel * turnoverQuantityNumLabel;   //成交量数量



@end

@implementation YJBTradeDetailHeaderView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
    }
    return self;
}


-(void)initView{
    CGFloat fontSize = 20;
    if (SCREEN_WIDTH == 320) {
        fontSize = 18;
    }
    self.backgroundColor = KColorWithRGBA(275, 203, 191, 1);
    
    UILabel * openPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH / 4, 15)];
    openPriceLabel.font = [UIFont systemFontOfSize:14];
    openPriceLabel.textColor = [UIColor grayColor];
    openPriceLabel.textAlignment = NSTextAlignmentCenter;
    openPriceLabel.text = @"开盘价(元)";
    [self addSubview:openPriceLabel];
    
    UILabel * openPriceTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(openPriceLabel.frame) + 10, SCREEN_WIDTH / 4, 15)];
    openPriceTextLabel.font = [UIFont systemFontOfSize:14];
    openPriceTextLabel.textColor = [UIColor blackColor];
    openPriceTextLabel.textAlignment = NSTextAlignmentCenter;
    openPriceTextLabel.text = @"0";
    [self addSubview:openPriceTextLabel];
    self.openPriceTextLabel = openPriceTextLabel;
    
    UILabel * closePriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 4, 10, SCREEN_WIDTH / 4, 15)];
    closePriceLabel.font = [UIFont systemFontOfSize:14];
    closePriceLabel.textColor = [UIColor grayColor];
    closePriceLabel.textAlignment = NSTextAlignmentCenter;
    closePriceLabel.text = @"收盘价(元)";
    [self addSubview:closePriceLabel];
    
    UILabel * closePriceTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 4, CGRectGetMaxY(openPriceLabel.frame) + 10, SCREEN_WIDTH / 4, 15)];
    closePriceTextLabel.font = [UIFont systemFontOfSize:14];
    closePriceTextLabel.textColor = [UIColor blackColor];
    closePriceTextLabel.textAlignment = NSTextAlignmentCenter;
    closePriceTextLabel.text = @"0";
    [self addSubview:closePriceTextLabel];
    self.closePriceTextLabel = closePriceTextLabel;
    
    UILabel * maxPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(2 * SCREEN_WIDTH / 4, 10, SCREEN_WIDTH / 4, 15)];
    maxPriceLabel.font = [UIFont systemFontOfSize:14];
    maxPriceLabel.textColor = [UIColor grayColor];
    maxPriceLabel.textAlignment = NSTextAlignmentCenter;
    maxPriceLabel.text = @"今最高价(元)";
    [self addSubview:maxPriceLabel];
    
    UILabel * maxPriceTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(2 * SCREEN_WIDTH / 4, CGRectGetMaxY(openPriceLabel.frame) + 10, SCREEN_WIDTH / 4, 15)];
    maxPriceTextLabel.font = [UIFont systemFontOfSize:14];
    maxPriceTextLabel.textColor = [UIColor blackColor];
    maxPriceTextLabel.textAlignment = NSTextAlignmentCenter;
    maxPriceTextLabel.text = @"0";
    [self addSubview:maxPriceTextLabel];
    self.maxPriceTextLabel = maxPriceTextLabel;
    
    
    UILabel * minPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(3 * SCREEN_WIDTH / 4, 10, SCREEN_WIDTH / 4, 15)];
    minPriceLabel.font = [UIFont systemFontOfSize:14];
    minPriceLabel.textColor = [UIColor grayColor];
    minPriceLabel.textAlignment = NSTextAlignmentCenter;
    minPriceLabel.text = @"今最低价(元)";
    [self addSubview:minPriceLabel];
    
    UILabel * minPriceTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(3 * SCREEN_WIDTH / 4, CGRectGetMaxY(minPriceLabel.frame) + 10, SCREEN_WIDTH / 4, 15)];
    minPriceTextLabel.font = [UIFont systemFontOfSize:14];
    minPriceTextLabel.textColor = [UIColor blackColor];
    minPriceTextLabel.textAlignment = NSTextAlignmentCenter;
    minPriceTextLabel.text = @"0";
    [self addSubview:minPriceTextLabel];
    self.minPriceTextLabel = minPriceTextLabel;
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(minPriceTextLabel.frame) + 10, SCREEN_WIDTH, 1)];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:lineView];
    
    UIView * dividerView = [[UIView alloc] initWithFrame:CGRectZero];
    dividerView.backgroundColor = [UIColor grayColor];
    dividerView.width = 1;
    dividerView.height = 20;
    dividerView.x = SCREEN_WIDTH / 4;
    dividerView.centerY = CGRectGetMinY(openPriceLabel.frame) + (15 + 10 + 15) / 2;
    
    UIView * dividerView2 = [[UIView alloc] initWithFrame:CGRectZero];
    dividerView2.backgroundColor = [UIColor grayColor];
    dividerView2.width = 1;
    dividerView2.height = 20;
    dividerView2.x = SCREEN_WIDTH  * 2 / 4;
    dividerView2.centerY = CGRectGetMinY(openPriceLabel.frame) + (15 + 10 + 15) / 2;
    
    UIView * dividerView3 = [[UIView alloc] initWithFrame:CGRectZero];
    dividerView3.backgroundColor = [UIColor grayColor];
    dividerView3.width = 1;
    dividerView3.height = 20;
    dividerView3.x = SCREEN_WIDTH * 3 / 4;
    dividerView3.centerY = CGRectGetMinY(openPriceLabel.frame) + (15 + 10 + 15) / 2;
    
    [self addSubview:dividerView];
    [self addSubview:dividerView2];
    [self addSubview:dividerView3];
    
    UILabel * averageLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, CGRectGetMaxY(openPriceTextLabel.frame) + 20, (SCREEN_WIDTH -15) / 4, 15)];
    averageLabel.textAlignment = NSTextAlignmentLeft;
    averageLabel.text = @"平均价格(元)";
    if (SCREEN_WIDTH <375) {
        averageLabel.text = @"平均价格";
    }
    averageLabel.textColor = [UIColor grayColor];
    averageLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:averageLabel];
    
    UILabel * averageTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, CGRectGetMaxY(averageLabel.frame) + 10, (SCREEN_WIDTH -15) / 4, 30)];
    averageTextLabel.font = [UIFont systemFontOfSize:fontSize];
    averageTextLabel.textAlignment = NSTextAlignmentCenter;
    averageTextLabel.text = @"0";
    averageTextLabel.textColor = KColorWithRGBA(218, 70, 28, 1);
    [self addSubview:averageTextLabel];
    self.averageLabel = averageTextLabel;
    
    UILabel * recentPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 4, CGRectGetMaxY(openPriceTextLabel.frame) + 20, (SCREEN_WIDTH -15) / 4, 15)];
    recentPriceLabel.textAlignment = NSTextAlignmentCenter;
    recentPriceLabel.text = @"最近价格(元)";
    if (SCREEN_WIDTH <375) {
        recentPriceLabel.text = @"最近价格";
    }

    recentPriceLabel.textColor = [UIColor grayColor];
    recentPriceLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:recentPriceLabel];
    
    UILabel * recentPriceTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 4 - 5, CGRectGetMaxY(recentPriceLabel.frame) + 10, (SCREEN_WIDTH - 15) / 4 + 10, 30)];
    recentPriceTextLabel.font = [UIFont systemFontOfSize:fontSize];
    recentPriceTextLabel.textAlignment = NSTextAlignmentCenter;
    recentPriceTextLabel.text = @"0";
    recentPriceTextLabel.textColor = MAIN_COLOR;
    [self addSubview:recentPriceTextLabel];
    self.recentPriceTextLabel = recentPriceTextLabel;
    
    //成交量
    UILabel * turnoverQuantityLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/4 *2 - 5, CGRectGetMaxY(openPriceTextLabel.frame) + 20, (SCREEN_WIDTH -15) / 4, 15)];
    turnoverQuantityLabel.textAlignment = NSTextAlignmentCenter;
    turnoverQuantityLabel.text = @"成交量";
    turnoverQuantityLabel.textColor = [UIColor grayColor];
    turnoverQuantityLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:turnoverQuantityLabel];
    
    UILabel * turnoverQuantityNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/4 *2, CGRectGetMaxY(recentPriceLabel.frame) + 10, (SCREEN_WIDTH -15) / 4, 30)];
    turnoverQuantityNumLabel.font = [UIFont systemFontOfSize:fontSize];
    turnoverQuantityNumLabel.textAlignment = NSTextAlignmentCenter;
    turnoverQuantityNumLabel.text = @"0";
    turnoverQuantityNumLabel.textColor = KColorWithRGBA(218, 70, 28, 1);
    [self addSubview:turnoverQuantityNumLabel];
    self.turnoverQuantityNumLabel = turnoverQuantityNumLabel;
    
    
    UILabel * changePriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(turnoverQuantityLabel.frame), CGRectGetMaxY(openPriceTextLabel.frame) + 20, (SCREEN_WIDTH -15) / 4, 15)];
    changePriceLabel.textAlignment = NSTextAlignmentCenter;
    changePriceLabel.text = @"今日涨跌";
    changePriceLabel.textColor = [UIColor grayColor];
    changePriceLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:changePriceLabel];
    
    UILabel * changePriceTextPointLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(turnoverQuantityNumLabel.frame), CGRectGetMaxY(changePriceLabel.frame) + 10, (SCREEN_WIDTH -15) / 4, 15)];
    changePriceTextPointLabel.font = [UIFont systemFontOfSize:14];
    changePriceTextPointLabel.textAlignment = NSTextAlignmentCenter;
    changePriceTextPointLabel.text = @"0";
    changePriceTextPointLabel.textColor = KColorWithRGBA(203, 158, 9, 1);
    [self addSubview:changePriceTextPointLabel];
    self.changePriceTextPointLabel = changePriceTextPointLabel;
    
    UILabel * changePriceTextPercentLabel = [[UILabel alloc] initWithFrame:CGRectMake(changePriceTextPointLabel.frame.origin.x, CGRectGetMaxY(changePriceTextPointLabel.frame) + 5, (SCREEN_WIDTH -15) / 4, 15)];
    changePriceTextPercentLabel.font = [UIFont systemFontOfSize:14];
    changePriceTextPercentLabel.textAlignment = NSTextAlignmentCenter;
    changePriceTextPercentLabel.text = @"0%";
    changePriceTextPercentLabel.textColor = KColorWithRGBA(203, 158, 9, 1);
    [self addSubview:changePriceTextPercentLabel];
    self.changePriceTextPercentLabel = changePriceTextPercentLabel;
    
}

-(void)setTraDetailModel:(YJBTradeDetailModel *)traDetailModel{
    
    _traDetailModel     = traDetailModel;
    
//    self.averageLabel.text = 
//    self.codeLabel.text = traDetailModel.code;
    
    self.openPriceTextLabel.text  = [NSString stringWithFormat:@"%.2f",[traDetailModel.openPrice floatValue]];
    self.closePriceTextLabel.text = [NSString stringWithFormat:@"%.2f",[traDetailModel.closePrice floatValue]];
    
    self.maxPriceTextLabel.text   = [NSString stringWithFormat:@"%.2f",[traDetailModel.highestPrice floatValue]];
    self.minPriceTextLabel.text   = [NSString stringWithFormat:@"%.2f",[traDetailModel.lowestPrice floatValue]];
    
    self.recentPriceTextLabel.text      = [NSString stringWithFormat:@"%.2f",[traDetailModel.price floatValue]];
    //成交量
    self.turnoverQuantityNumLabel.text  = [NSString stringWithFormat:@"%ld",traDetailModel.turnoverQuantity ];
    self.changePriceTextPointLabel.text = [NSString stringWithFormat:@"%.2f",[traDetailModel.riseAmount floatValue]];
    
    self.changePriceTextPercentLabel.text = [NSString stringWithFormat:@"%.2f%%",[traDetailModel.riseScale floatValue]];
    
    CGFloat percent = [traDetailModel.riseAmount floatValue];
    if (percent >= 0) {
        self.backgroundColor = KColorWithRGBA(275, 203, 191, 1);
        
    }else{
        self.backgroundColor = KColorWithRGBA(178, 218, 189, 1);
        
    }
    
}

@end
